home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr43 / sbdsp2b.zip / WAV2RPD.PAS < prev   
Pascal/Delphi Source File  |  1995-01-04  |  5KB  |  126 lines

  1. Program WAV2RPD;
  2.  
  3. (**************************************************************************)
  4. (*                            Program WAV2RPD                             *)
  5. (*                       By: Romesh Prakashpalan                          *)
  6. (**************************************************************************)
  7. (*  This program is similar to my VOC2RPD program in that it converts a   *)
  8. (* WAV file to the RPD format. A WAV file is considerably easier to       *)
  9. (* convert than a VOC file, as there aren't that many Block Types!        *)
  10. (**************************************************************************)
  11.  
  12. Uses SBDSP, Crt;
  13.  
  14. (**************************************************************************)
  15. (* Revisions:                                                             *)
  16. (*   *Version 1.0a: Current Version                                       *)
  17. (**************************************************************************)
  18. type
  19.   ChunkType = Record
  20.                 ID: Array [1..4] of Char;      (* "RIFF" *)
  21.                 Len: LongInt;                  (* Size of the Data Chunk *)
  22.               end;
  23.  
  24.  
  25.   DataType = Record    (* For a Wave Type File *)
  26.                 ID: Array [1..4] of Char;      (* "WAVE" *)
  27.               end;
  28.   FormatChunkType = Record
  29.                  ChunkID: Array [1..4] of Char; (* "fmt" *)
  30.                  Len: LongInt;         (* Size of Data *)
  31.                  FormatTag: Word;      (* 01 = PCM     *)
  32.                  Channels: Word;       (* 1 = Mono, 2 = Stereo *)
  33.                  SamplesPerSec: Word;  (* PlayBack Freq *)
  34.                  AvgBytesPerSec: Word;
  35.                  BlockAlign: Word;
  36.                  FormatSpecific: Word;
  37.                end;
  38.  
  39.   RPDHeader = Record
  40.                 Sig: Array [0..2] of Char; (* "RPD" *)
  41.                 Version: Word;             (* Version # *)
  42.                 DAC: Byte;                 (* 16/8/4/4.6/2/2.6, etc...*)
  43.                 Phase: Byte;               (* Mono=0, Stereo=1, Surround=2 *)
  44.                 Freq: Word;                (* Sample Frequency *)
  45.                 Channels: Byte;            (* # of DIGITAL Channels *)
  46.                 ChannelMethod: Byte;       (* Method for laying down channels *)
  47.                 Size: LongInt;             (* Size of Sample *)
  48.                 Reserved: Array [0..31] of Byte;
  49.               end;
  50.  
  51. var
  52.   Source, Destination: String;
  53.   Ch: Char;
  54.  
  55. Procedure ConvertWAV2RPD (Source, Destination: String);
  56. var
  57.   SourceF, DestF: File;
  58.   TempRPDHead: RPDHeader;
  59.   TempChunk: ChunkType;
  60.   TempData: DataType;
  61.   TempFormatChunk: FormatChunkType;
  62.   TempBuffer: Pointer;
  63.   NumRead, NumWritten: Word;
  64. Begin
  65.   GetMem (TempBuffer, $FFFF);
  66.   Assign (SourceF, Source);
  67.   Assign (DestF, Destination);
  68.   Reset (SourceF, 1);
  69.   Rewrite (DestF, 1);
  70.   BlockRead (SourceF, TempChunk, SizeOf (TempChunk));
  71.   BlockRead (SourceF, TempData, SizeOf (TempData));
  72.   BlockRead (SourceF, TempFormatChunk, SizeOf (TempFormatChunk));
  73.   TempRPDHead.Sig := 'RPD';
  74.   TempRPDHead.Version := 1;
  75.   TempRPDHead.DAC := EightBitDMA;
  76.   TempRPDHead.Phase := TempFormatChunk.Channels - 1;
  77.   TempRPDHead.Channels := TempFormatChunk.Channels;
  78.   TempRPDHead.Freq := TempFormatChunk.BlockAlign;
  79.   TempRPDHead.ChannelMethod := 0;
  80.   TempRPDHead.Size := FileSize (SourceF) - FilePos (SourceF);
  81.   BlockWrite (DestF, TempRPDHead, SizeOf (TempRPDHead));
  82.   Repeat
  83.     BlockRead(SourceF, TempBuffer^, $FFFF, NumRead);
  84.     BlockWrite(DestF, TempBuffer^, NumRead, NumWritten);
  85.   Until (NumRead = 0) or (NumWritten <> NumRead);
  86.   Close (SourceF);
  87.   Close (DestF);
  88.   FreeMem (TempBuffer, $FFFF);
  89. End;
  90.  
  91. Function FileExists (Filename: String): Boolean;
  92. var
  93.  F: file;
  94. Begin
  95.  {$I-}
  96.  Assign(F, FileName);
  97.  FileMode := 0;      (* Set file access to read only *)
  98.  Reset(F);
  99.  Close(F);
  100.  {$I+}
  101.  FileExists := (IOResult = 0) and (FileName <> '');
  102. End;
  103.  
  104. Begin
  105.   Clrscr;
  106.   WriteLn ('           WAV2RPD version 1.0a, By: Romesh Prakashpalan, 1994');
  107.   WriteLn ('                            WAV2RPD is FREEWARE             ');
  108.   Write ('Enter in WAV file to be converted: ');
  109.   ReadLn (Source);
  110.   If not FileExists (Source) then
  111.   Begin
  112.     WriteLn ('Source File Doesn''t Exist!');
  113.     Halt;
  114.   End;
  115.   Write ('Enter in RPD file to convert to: ');
  116.   ReadLn (Destination);
  117.   If FileExists (Destination) then
  118.   Begin
  119.     Write ('File exists! overwrite? (''N'' for No, any other key kills it): ');
  120.     Ch := UpCase (Readkey);
  121.     WriteLn (Ch);
  122.     If Ch = 'N' then Halt;
  123.   End;
  124.  
  125.   ConvertWAV2RPD (Source, Destination);
  126. End.